## Table A13: Effects of Lagged Differential Demand on Wait Times: Across Cities, Within Common Service

## install.packages(c("tidyverse", "fixest"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("demand_common_services.RData")

## Column 1
race_wait_demand_lag <- feols(log_norm_mean_wait ~ lag_non_white_demand |
                                common_service^open_month^open_year, 
                              data = demand_common_services, 
                              weights = demand_common_services$tot_calls,
                              cluster = "city_common_service")

## Column 2
race_wait_need_lag <- feols(log_norm_mean_wait ~ lag_non_white_need |
                              common_service^open_month^open_year, 
                            data = demand_common_services, 
                            weights = demand_common_services$tot_calls,
                            cluster = "city_common_service")

## Column 3
income_wait_demand_lag <- feols(log_norm_mean_wait ~ lag_poor_demand |
                                  common_service^open_month^open_year, 
                                data = demand_common_services, 
                                weights = demand_common_services$tot_calls,
                                cluster = "city_common_service")

## Column 4
income_wait_need_lag <- feols(log_norm_mean_wait ~ lag_poor_need |
                                common_service^open_month^open_year, 
                              data = demand_common_services, 
                              weights = demand_common_services$tot_calls,
                              cluster = "city_common_service")

## Column 5
race_expected_demand_lag <- feols(log_norm_mean_expected ~ lag_non_white_demand |
                                    common_service^open_month^open_year, 
                                  data = demand_common_services, 
                                  weights = demand_common_services$tot_calls,
                                  cluster = "city_common_service")

## Column 6
race_expected_need_lag <- feols(log_norm_mean_expected ~ lag_non_white_need |
                                  common_service^open_month^open_year, 
                                data = demand_common_services, 
                                weights = demand_common_services$tot_calls,
                                cluster = "city_common_service")

## Column 7
income_expected_demand_lag <- feols(log_norm_mean_expected ~ lag_poor_demand |
                                      common_service^open_month^open_year, 
                                    data = demand_common_services, 
                                    weights = demand_common_services$tot_calls,
                                    cluster = "city_common_service")

## Column 8
income_expected_need_lag <- feols(log_norm_mean_expected ~ lag_poor_need |
                                    common_service^open_month^open_year, 
                                  data = demand_common_services, 
                                  weights = demand_common_services$tot_calls,
                                  cluster = "city_common_service")

TableA13 = etable(race_wait_demand_lag, race_wait_need_lag,
                  income_wait_demand_lag, income_wait_need_lag,
                  race_expected_demand_lag, race_expected_need_lag,
                  income_expected_demand_lag, income_expected_need_lag,
                  signifCode = c("+" = 0.10, "*" = 0.05, "**" = 0.01, "***" = 0.001),
                  digits = 3, digits.stats = 3, fitstat = c("n","r2"))